﻿
Imports System.Net

Public Class IPEndPoint2
    Inherits IPEndPoint
    Implements ICloneable, IComparable, IComparable(Of IPEndPoint), IComparable(Of IPEndpoint2)

    Public Sub New(ByVal address As Int64, ByVal port As Int32)
        MyBase.New(address, port)
    End Sub

    Public Sub New(ByVal address As IPAddress, ByVal port As Int32)
        MyBase.New(address, port)
    End Sub

    Public Overloads Shared Function create(ByVal address As String, ByVal port As Int32) As IPEndPoint
        Return New IPEndPoint(IPAddress2.create(address), port)
    End Function

    Public Function Clone() As Object Implements ICloneable.Clone
        Return New IPEndpoint2(Address, Port)
    End Function

    Public Function CompareTo(ByVal obj As Object) As Int32 Implements IComparable.CompareTo
        Return CompareTo(convertor.cast(Of IPEndPoint)(obj, False))
    End Function

    Public Function CompareTo(ByVal other As IPEndPoint) As Int32 Implements IComparable(Of IPEndPoint).CompareTo
        If other Is Nothing Then
            Return 1
        Else
            Dim cmp As Int32 = 0
            cmp = IPAddress2.compare(Address, other.Address)
            If cmp = 0 Then
                Return compare(Port, other.Port)
            Else
                Return cmp
            End If
        End If
    End Function

    Public Function CompareTo(ByVal other As IPEndpoint2) As Int32 Implements IComparable(Of IPEndpoint2).CompareTo
        Return CompareTo(convertor.cast(Of IPEndPoint)(other, False))
    End Function
End Class
